// DrawElement.cpp: implementation of the CDrawElement class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DrawElement.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CDrawElement,CObject,1)
double CDrawElement::dscrx=0.75;
double CDrawElement::dscry=0.75;
CDrawElement::CDrawElement()
{
	bIsSelected=0;
	startX=30;
	startY=21;
	endX=30+100*(CDrawElement::dscrx*4/3);
	endY=21+100*(CDrawElement::dscry*4/3);
	//	dscrx=0.75;
	//	dscry=0.75;
	LineWidth=1;
	LineColor=RGB(0,0,0);
	LineStyle=PS_SOLID;
	
	m_bFill=FALSE;
	BrushColor=RGB(255,255,255);
	//BrushColor = PALETTEINDEX(100);
}

CDrawElement::~CDrawElement()
{
	
}

void CDrawElement::Serialize(CArchive & ar)
{
	CObject::Serialize(ar);
    if(ar.IsLoading())
    {
    }
	else
	{
    }
}

void CDrawElement::Draw(CDC *pDC)
{
	
}

void CDrawElement::ShowProperties()
{
	
}

void CDrawElement::setWidth(int width)
{
	this->endX = (startX+width);
}

void CDrawElement::setHeight(int height)
{
	this->endY = startY+height;
}

void CDrawElement::parsePosStr(CString posStr)
{
	
}
d_vt_tmpstrinfo CDrawElement::DStrSlp(CString m_str, CString m_flag)
{
	vector<CString> tp_vt;
	int i=0;
	while(true){
		m_str.Replace(m_flag,"$");
		CString sOccupation="";
		if(AfxExtractSubString ( sOccupation, m_str, i, '$')){
			tp_vt.push_back(sOccupation);
			i=i+1;
		}else{
			break;
		}
	}
	return tp_vt;
}

COLORREF CDrawElement::parseColorStr(CString colorStr){
	colorStr.Replace("(","");
	colorStr.Replace(")","");
	vector<CString> tp_vtt = DStrSlp(colorStr,",");
	int j=0;
	int R=0;
	int G=0;
	int B=0;
	for(vector<CString>::iterator tp_iiii= tp_vtt.begin();tp_iiii!= tp_vtt.end();tp_iiii++){
		j++;
		if(j==1){
			
		}
		else if(j==2){
			R=atoi(*tp_iiii);
		}
		else if(j==3){
			G=atoi(*tp_iiii);
		}
		else if(j==4){
			B=atoi(*tp_iiii);
		}
	}
	return RGB(R,G,B);
	
}


CString CDrawElement::getPosStr()
{
	CString str="";
	CString strTmp;
	int tmp=0;
	tmp=startX/(CDrawElement::dscrx)+0.5;//+5/(CDrawElement::dscrx*4/3);
	strTmp.Format("%d:",tmp);//top
	str+=strTmp;
	tmp=startY/(CDrawElement::dscry)+0.5;//+5/(CDrawElement::dscrx*4/3);
	strTmp.Format("%d:",tmp);//left
	str+=strTmp;
//	30+100*(CDrawElement::dscrx*4/3)
	tmp=(endX-startX)/(CDrawElement::dscrx);//+30/(CDrawElement::dscrx*4/3);
	strTmp.Format("%d:",tmp);//bottom
	str+=strTmp;
	tmp=(endY-startY)/(CDrawElement::dscry);//+30/(CDrawElement::dscrx*4/3);
	strTmp.Format("%d",tmp);//right
	str+=strTmp;
	//str+="\"";
	return str;
}
